/**
 *从历史业务数据载入模版数据
 *bizId 三种业务统一的业务ID
 *bizType = [all, C, D, F]，分别代表all,拖车,货代,报关
 *platformVersion 平台版本 2.0还是3.0
 */
function loadBizFromHistoryData(bizId, id, bizType, isRecordInfo, platformVersion,isTongguanYth, type,  dType) {
    if ("2.0" === platformVersion) {
        loadBizFromHistoryData2_0(bizId, bizType, isRecordInfo);
    } else {
        loadBizFromHistoryData3_0(id, bizType,isTongguanYth, type,  dType);
    }
}

/**
 * 2.0加载模板的方法
 *bizId 三种业务统一的业务ID
 *bizType = [all, C, D, F]，分别代表all,拖车,货代,报关
 * @param isRecordInfo
 */
function loadBizFromHistoryData3_0(bizId, bizType,isTongguanYth,type,dType) {
    location.href = "/business/order_custom_page_pick_model?bizId=" + bizId + "&bizType=" + bizType + "&isTongguanYth="+isTongguanYth
                    + "&type="+ type + "&dType="+ dType ;

    // $("body").load('/business/order_custom_page_pick_model',{
    //     bizId:bizId, bizType:bizType
    // },function(a, b, c){
    //     if(c.status == 500){
    //         alert("加载失败。");
    //     }else if(c.status == 200){
    //         alert("加载成功。");
    //     }
    // });
}

/**
 * 2.0加载模板的方法
 * @param bizId
 * @param bizType
 * @param isRecordInfo
 */
function loadBizFromHistoryData2_0(bizId, bizType, isRecordInfo) {
    //load data
    //set data
    var data = "bizId=" + bizId + "&bizType=" + bizType + "&isRecordInfo" + isRecordInfo;
    $
        .ajax({
                  url: "business-loadBizFromHistoryData",
                  cache: false,
                  async: false,
                  dataType: "json",
                  data: data,
                  success: function (data) {
                      //set shipper
                      //debugger
                      initInputByJsonObj(data.shipper, "shipper");
                      if (data.book && data.book.id && data.book.id != "" && bizType
                                                                             == "booking") {
                          $("#book").attr("checked", true);
                          busi("book", 'business-booking?clearPk=1&book.id=' + data.book.id,
                               '订舱', {async: false});
                      }
                      if (data.declare && data.declare.id && data.declare.id != ""
                          && bizType == "declaration") {
                          if (isRecordInfo == 'T') {
                              $("#declarate").attr("checked", true);
                              busi("declarate",
                                   'business-declarationMain?clearPk=1&modelType=1&id='
                                   + data.declare.id, '手册报关', {async: false});
                          } else if (isRecordInfo == 'F') {
                              $("#declarate1").attr("checked", true);
                              busi("declarate1",
                                   'business-declarationMain?clearPk=1&modelType=1&id='
                                   + data.declare.id, '非手册报关', {async: false});
                          }
                      }
                      if (data.trial && data.trial.id && data.trial.id != "" && bizType
                                                                                == "trail") {
                          $("#trail").attr("checked", true);
                          busi("trail", 'business-trailModel?clearPk=1&id=' + data.trial.id,
                               '拖车', {
                                   async: false, success: function () {
                                      $("#trial_info_show").show();
                                      $("#trial_gd_input tr:gt(4)").find("span").each(
                                          function (i, n) {
                                              if (i == 0) {
                                                  countSizeType($("#gd_ctNumType"),
                                                                "", 1);
                                              } else {
                                                  countSizeType(
                                                      $("#gd_ctNumType_" + i),
                                                      i, 1);
                                              }
                                          });
                                  }
                               });
                      }

                      if (bizType == "all") {
                          if (data.book && data.book.id && data.book.id != "") {
                              $("#book").attr("checked", true);
                              busi("book",
                                   'business-booking?clearPk=1&book.id=' + data.book.id,
                                   '订舱', {async: false});
                          }
                          if (data.declare && data.declare.id && data.declare.id != "") {
                              if (isRecordInfo == 'T') {
                                  $("#declarate").attr("checked", true);
                                  busi("declarate",
                                       'business-declarationMain?clearPk=1&modelType=1&id='
                                       + data.declare.id, '手册报关', {async: false});
                              } else if (isRecordInfo == 'F') {
                                  $("#declarate1").attr("checked", true);
                                  busi("declarate1",
                                       'business-declarationMain?clearPk=1&modelType=1&id='
                                       + data.declare.id, '非手册报关', {async: false});
                              }
// 								$("#declarate").attr("checked", true);
// 								busi("declarate",
// 'business-declarationMain?clearPk=1&modelType=1&id=' + data.declare.id,
// '报关',{async:false},"1");//1为模板参数。否则不是模板导入
                          }
                          if (data.trial && data.trial.id && data.trial.id != "") {
                              $("#trail").attr("checked", true);
                              busi("trail", 'business-trailModel?clearPk=1&modelType=1&id='
                                            + data.trial.id, '拖车', {
                                       async: false, success: function () {
                                      $("#trial_info_show").show();
                                      $("#trial_gd_input tr:gt(4)").find("span").each(
                                          function (i, n) {
                                              if (i == 0) {
                                                  countSizeType($("#gd_ctNumType"), "",
                                                                1);
                                              } else {
                                                  countSizeType($("#gd_ctNumType_" + i),
                                                                i, 1);
                                              }
                                          });
                                  }
                                   });
                          }
                      }
                  }
              });
// 		var focusElement = document.getElementById('company');
// 		focusElement.focus();
}
